package com.hxb.api.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import com.hxb.api.entity.ApiLog;
import com.hxb.util.jdbc.JdbcUtils;

public class ApiLogDao {
        
	private JdbcUtils jdbcUtils = null;
	
	public ApiLogDao() {
		jdbcUtils = new JdbcUtils();
	}

	public boolean insert(ApiLog log){
		String sql = "INSERT INTO  API_LOG(ID, API_ID,API_NAME,API_URL,IP_ADDR,ACCESS_TIME,TOTAL_COST_TIME,SERVER_COST_TIME,AJAX_COST_TIME) values (?,?,?,?,?,?,?,?,?)";
		List<Object> params = new ArrayList<Object>();
		params.add(generateId());
		params.add(log.getApiId());
		params.add(log.getApiName());
		params.add(log.getApiUrl());
		params.add(log.getIpAddr());
		params.add(log.getAccessTime());
		params.add(log.getTotalCostTime());
		params.add(log.getServerCostTime());
		params.add(log.getAjaxCostTime());
		boolean flag = false;
		try {
			flag = jdbcUtils.updateByPreparedStatement(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return flag;
	}

	private long generateId() {
		return System.currentTimeMillis();
	}
}
